﻿using GameDataTempshitEditor.Widgets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GameDataTempshitEditor.DataEditors
{
    /// <summary>
    /// Property editor for enumeration value
    /// </summary>
    class GameData_PropertyEditor_Enum : PropertyItemEditor_Choice
    {
        public readonly Red.GameData.Raw.ReflectionEnum _Enum;

        public GameData_PropertyEditor_Enum(PropertyItemBase Item, Red.GameData.Raw.ReflectionEnum rawEnum)
            : base(Item)
        {
            _Enum = rawEnum;
        }

        public override void GetOptions(ref List<ComboOption> options)
        {
            foreach (var str in _Enum.Options)
            {
                options.Add(new ComboOption(str.Name));
            }
        }

        public override bool ValidateValue(string value, ref string errorMessage)
        {
            foreach (var option in _Enum.Options)
                if (value == option.Name)
                    return true;

            errorMessage = "Value is not valid enum option";
            return false;
        }
    }
}
